$(function(){
	
	$(".particularsMessageTab li").click(function(){
		$(this).addClass("first").siblings().removeClass("first");
		var index=$(this).index();
		$(".text").eq(index).css("display","block").siblings('.text').css("display","none");
	})
	
	layui.use(['Zutil'], function() {
		var Zutil = layui.Zutil;
		var obj={};
		obj.offerId=Zutil.getQueryString("offerId");
		
		var categoryObj={};
		var categoryIdObj={};
		$.ajax({
			type:"post",
			url:"/guidance_service/front/market/category/search.do",
			async:false,
			data:obj,
			success:function(obj){
				console.log(obj)
				var categoryBaseObj=obj.data;
				$.each(categoryBaseObj,function(i,category){
					categoryObj[this.categoryCode]=this;
					categoryIdObj[this.categoryId]=this;
				});
			}
		});
		$.ajax({
		    type:"post",
		    url:"/guidance_service/front/market/offer/searchDetail.do",
		    data:obj,
		    success : function (result){
		        console.log(result)
		        var data = result.data;
				if(result.resultCode == 200){
					if(data.taxRate){
						$("#taxRate span").html(data.taxRate);
					}else{
						$("#taxRate").hide();
					}
					var areaStr="";
					if(data.areaCode){
						areaStr=areaStr+areaObj[data.areaCode.substr(0,2)+"0000"];
						areaStr=areaStr+areaObj[data.areaCode.substr(0,4)+"00"];
						areaStr=areaStr+areaObj[data.areaCode.substr(0,6)];
					}
					if(areaStr){
						$("#areaName span").html(areaStr);
					}else{
						$("#areaName").hide();
					}
					var  categoryId= data.categoryId;
					if(categoryIdObj[categoryId]){
						var materialObj=categoryIdObj[categoryIdObj[categoryId].categoryParentId];
					}
					var specificcationsHtml="";
					if(materialObj){
						$("#materialName").html(materialObj.categoryName);
						$(".MessageName").html(materialObj.categoryName);
						specificcationsHtml=specificcationsHtml+"<li>材料名称：<span>"+materialObj.categoryName+"</span></li>";
					}
					
					var specificcations;
					if(data.specificcations){
						specificcations=JSON.parse(data.specificcations);
						for(var i=0;i<specificcations.length;i++){
							$.each(specificcations[i],function(index,obj){
								if(index!="品种"){
									specificcationsHtml=specificcationsHtml+"<li>"+index+"：<span>"+obj+"</span></li>";
								}
							});
						}
					}
					$(".technologyUl").html(specificcationsHtml);
					if(categoryIdObj[categoryId]&&categoryIdObj[categoryIdObj[categoryId].categoryParentId]){
						var parentCategoryObj=categoryIdObj[categoryIdObj[categoryIdObj[categoryId].categoryParentId].categoryParentId];
					}
					if(parentCategoryObj){
						$(".categoryName").html(parentCategoryObj.categoryName);
					}
					$(".maxTaxPrice").html(data.maxTaxPrice);
					$(".minTaxPrice").html(data.minTaxPrice);
					$(".maxNoTaxPrice").html(data.maxNoTaxPrice);
					$(".minNoTaxPrice").html(data.minNoTaxPrice);
					$("#illustration").html(data.illustration);
					var realShotPicArr;
					if(data.realShotPic){
						realShotPicArr=data.realShotPic.split(",");
					}else{
						realShotPicArr=[];
					}
					for(var i=0;i<realShotPicArr.length;i++){
						$(".technologyImg").append("<img src='"+realShotPicArr[i]+"'/>");
					}
					if(data.materialPic){
						$(".MessageImg").attr("src",data.materialPic);
					}else if(data.specificcationsImg){
						$(".MessageImg").attr("src",data.specificcationsImg);
					}else if(data.materialImg){
						$(".MessageImg").attr("src",data.materialImg);
					}
					var detailPicArr;
					if(data.detailPic){
						detailPicArr=data.detailPic.split(",");
					}else{
						detailPicArr=[];
					}
					for(var i=0;i<detailPicArr.length;i++){
						$("#detailPic").append("<img src='"+detailPicArr[i]+"'/>");
					}
					var featureArr;
					if(data.feature){
						featureArr=data.feature.split(",");
					}else{
						featureArr=[];
					}
					for(var i=0;i<featureArr.length;i++){
						$("#feature").append("<img src='"+featureArr[i]+"'/>");
					}
					var inspectionReportArr;
					if(data.inspectionReport){
						inspectionReportArr=data.inspectionReport.split(",");
					}else{
						inspectionReportArr=[];
					}
					for(var i=0;i<inspectionReportArr.length;i++){
						$("#inspectionReport").append("<img src='"+inspectionReportArr[i]+"'/>");
					}
					if(data.productManuals){
						var productManuals=JSON.parse(data.productManuals);
						$("#productManuals").click(function(){
							window.open(productManuals.url);
						});
					}
					if(!data.inspectionReport){
						$(".detection").remove();
						$(".particularsMessageTab li").eq(2).remove();
						$(".particularsMessageTab li").width(1240/$(".particularsMessageTab li").length);
					}
					if((!data.detailPic)&&(!data.feature)&&(!data.illustration)){
						$(".specimen").remove();
						$(".particularsMessageTab li").eq(1).remove();
						$(".particularsMessageTab li").width(1240/$(".particularsMessageTab li").length);
					}
					
					$(".showSupplier").click(function(){
						if(data.supplierId){
							window.open("supplier.html?supplierId="+data.supplierId);
						}else{
							return;
						}
					});
				}else{
					layer.msg(result.message,{icon:2,time:2000})
				}
		        
		    },error : function (e){
		        layer.msg("请求错误,请稍后重试",{icon:2,time:2000})
		    }
		});
	});
	
	function getCategory(){
		$.ajax({
			type:"post",
			url:"/guidance_service/front/market/category/search.do",
			async:false,
			data:{},
			success:function(obj){
				categoryObj=obj.data;
			}
		});
		return categoryObj;
	}
	})	
